<template>
	<view class="actives">
		<view class="uni-form-item uni-column">
			<view class="title">邀请码：</view>
			<input class="uni-input" v-model="invitecode" placeholder="请填写邀请码"
				placeholder-style="color:#939393;font-size:28rpx" />
		</view>

		<button type="default" class="active_btn" @click="doSave">保存</button>
	</view>
</template>

<script>
	import {
		addresslist
	} from "@/api/my/address.js"
	export default {
		data() {
			return {
				invitecode: "", //邀请码
			}
		},
		methods: {
			doSave() {
				let invitecode = this.invitecode
				// 邀请码 6位 字母数字
				let reg = /^[0-9A-Za-z]{6}$/
				let test = reg.test(invitecode)
				if (!invitecode || invitecode.length !== 6 || !test) {
					uni.showToast({
						icon: 'none',
						duration: 3000,
						title: `请输入正确邀请码`
					});
				} else {
					this.doOperate();
				}
			},

			doOperate() {
				uni.showLoading({
					title: '提交中'
				});
				addresslist('bindFans', {
					invitation_code: this.invitecode
				}).then(res => {
					uni.hideLoading();
					if (res.code == 200) {
						this.$store.dispatch("updateUserInfo");
						uni.navigateBack();
					}
				}).catch(error => {
					uni.hideLoading();
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import "../my.scss";

	.actives {
		padding: 60rpx 20rpx;
		color: #383838;
		font-size: 28rpx;

		.uni-form-item {
			line-height: 100rpx;
			@include flexLayout(center, flex-start);
			border-bottom: 2rpx solid #eff2f5;
			padding-top: 10rpx;
		}

		.active_btn {
			position: fixed;
			bottom: 50rpx;
			left: 0;
			width: 80%;
			height: 84rpx;
			line-height: 84rpx;
			background: linear-gradient(360deg, #EE4629 0%, #EE653A 100%);
			box-shadow: 0px 20rpx 36rpx 0px rgba(238, 73, 43, 0.25);
			border-radius: 42rpx;
			margin: 120rpx 10%;
			color: #FFFFFF;
			font-size: 36rpx;
			font-weight: 500;
		}
	}
</style>
